<script type="text/javascript">
$(document).ready(function(){
	//$(".show2").hide();
	pilih_data();
	
	$("#periode").change(function(){
		var periode = $("#periode").val();
		if(periode == 1){
			document.getElementById('tgl1').disabled = false;
			document.getElementById('tgl2').disabled = false;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}
		else if(periode == 2){
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}else{
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = true;
			document.getElementById('bln2').disabled = true;
		}
	});
	$("#pilihan1").change(function(){
		var pil = $("#pilihan1").val();
		if(pil == 1){
			$(".kec").show(250);
		}else{
			$(".kec").hide();
		}
	});
	
	$("#pilihan3").change(function(){
		var pil = $("#pilihan3").val();
		if(pil == 1){
			$(".kec").show(250);
		}else{
			$(".kec").hide();
		}
	});
	
	$("#dimensi").change(function(){
		pilih_data();
	});
});
function pilih_data(){
	var dimensi = $("#dimensi").val();
	var pilihan1 = $("#pilihan1").val();
	var pilihan3 = $("#pilihan3").val();
		if(dimensi == 2){
			$(".show1").hide();
			$(".show2").show(250);
			if(pilihan3 == 1){
				$(".kec").show(250);
			}else{
				$(".kec").hide();
			}
		}else{
			$(".show1").show();
			$(".show2").hide(250);
			if(pilihan1 == 1){
				$(".kec").show(250);
			}else{
				$(".kec").hide();
			}
		}
}
</script>
<?php
	$tgl = date("d");
	$bln = date("m");
	$thn = date("Y");
	$dimensi = $_POST['dimensi'];
	if($dimensi=='2'){
		$status_show1='none';
		$status_show2='';
	}else{
		$status_show1='';
		$status_show2='none';
	}
	
	$pilihan1 = $_POST['pilihan1'];
	if($pilihan1=='1'){
		$status_kec='';
	}else if($pilihan3=='1'){
		$status_kec='';
	}else{
		$status_kec='none';
	}
	
	$periode = $_POST['periode'];
	$tgl1 = $_POST['tgl1'];
	$tgl2 = $_POST['tgl2'];
	$bln1 = $_POST['bln1'];
	$bln2 = $_POST['bln2'];
	$thn1 = $_POST['thn1'];
	$thn2 = $_POST['thn2'];
	
	$pilihan1 = $_POST['pilihan1'];
	$pilihan2 = $_POST['pilihan2'];
	$pilihan3 = $_POST['pilihan3'];
	
	$kecamatan = $_POST['kecamatan'];
	
	$pilihan = $_POST['pilihan'];
	$urut = $_POST['urut'];
	$jumlah = $_POST['jumlah'];
	$tarif = $_POST['tarif'];
	$jenis_urut = $_POST['jenis_urut'];
	$tarif_ditanggung = $_POST['tarif_ditanggung'];
	//buat jumlah
	$count_tampil=0;
	if(isset($jumlah)){
		$str_jumlah="checked";
		$tampil_jumlah="";
		$count_tampil++;
	}else{
		$str_jumlah="";
		$tampil_jumlah="none";
	}
	
	//buat tarif
	if(isset($tarif)){
		$str_tarif="checked";
		$tampil_tarif="";
		$count_tampil++;
	}else{
		$str_tarif="";
		$tampil_tarif="none";
	}
	
	//buat tarif ditanggung
	if(isset($tarif_ditanggung)){
		$str_tarif_ditanggung="checked";
		$tampil_tarif_ditanggung="";
		$count_tampil++;
	}else{
		$str_tarif_ditanggung="";
		$tampil_tarif_ditanggung="none";
	}
	//$str_jumlah=isset($jumlah)?"checked" : "";
	//$str_tarif=isset($tarif)?"checked" : "";
	//$str_tarif_ditanggung=isset($tarif_ditanggung)?"checked" : "";
	
	//echo "<pre>";
	//print_r($_POST);
?>
<div id="tiga_ba">
	<div id="tiga_baa">Laporan Statistik Klaim </div>
	<div id="tiga_bab">
		
	</div>
	<div class="clear"></div>
</div>

<form method=post action='utama.php?module=mod_statistik&view=klaim'>
	<table style="margin-left: 5px;">
	<tr>
		<td>Dimensi</td>
		<td>
		<?php
			$arr_dimensi=array('1'=>'1 Dimensi','2'=>'2 Dimensi');
			kombo_from_array("dimensi","input2",$arr_dimensi,$dimensi);
				?>
		</td>
		<td>
				<span style="display:<?php echo $status_show1;?>" class="show1">
					Baris
				</span>
				<span style="display:<?php echo $status_show2;?>" class="show2">
					Kolom
				</span>
			</td>
			<td>
				<span style="display:<?php echo $status_show2;?>" class="show2">
				<?php
				$arr_jenis=array('3'=>'Umur','4'=>'Jenis Peserta','5'=>'Agama','6'=>'Jenis Kelamin');
			kombo_from_array("pilihan2","input2",$arr_jenis,$pilihan2);
				?>
				</span>
				<span style="display:<?php echo $status_show1;?>" class="show1">
				<?php
			
			$arr_jenis=array('1'=>'Desa','2'=>'Kecamatan','3'=>'Umur','4'=>'Jenis Peserta','5'=>'Agama',
					'6'=>'Jenis Kelamin','diagnosis'=>'Diagnosis','inacbg'=>'INA-CBG','lab'=>'Laboratorium',
						'layanan'=>'Layanan','tindakan'=>'Tindakan','prosedur'=>'Prosedur',
						'obat'=>'Obat','abhp'=>'ABHP','radiologi'=>'Radiologi');
			kombo_from_array("pilihan1","input2",$arr_jenis,$pilihan1);
				?>	
				</span>
			</td>
	</tr>
		<tr>
			<td width="75">Periode </td>
			<td width="300">
				<select name="periode" id="periode" class="input1">
					<?php
						if($periode == 1){
							$s1 = "selected";
						}else if($periode == 2){
							$p1 = "disabled";
							$s2 = "selected";
						}else{
							$p1 = "disabled";
							$p2 = "disabled";
							$s3 = "selected";
						}
					?>
					<option value="1" <?php echo $s1; ?>>Hari</option>
					<option value="2" <?php echo $s2; ?>>Bulan</option>
					<option value="3" <?php echo $s3; ?>>Tahun</option>
				</select>
			</td>
			<td valign="top" style="padding-top: 10px;">
				<span style="display:<?php echo $status_show2;?>" class="show2">Baris</span>
			</td>
			<td>
				<span style="display:<?php echo $status_show2;?>" class="show2">
				<?php
					//$arr_jenis=array('1'=>'Desa','2'=>'Kecamatan','3'=>'Umur','4'=>'Jenis Peserta','5'=>'Agama','6'=>'Jenis Kelamin');
					//kombo_from_array("pilihan3","input2",$arr_jenis,$pilihan3);
			$arr_jenis=array('1'=>'Desa','2'=>'Kecamatan','3'=>'Umur','4'=>'Jenis Peserta','5'=>'Agama','6'=>'Jenis Kelamin');
			kombo_from_array("pilihan3","input2",$arr_jenis,$pilihan3);
				?>	
				</span>
				<span style="display:<?php echo $status_kec;?>" class="kec">
					<?php
						kombo_kec("kecamatan","input2","kecamatan","$kecamatan");
					?>
				</span>
			</td>
			
		</tr>
		<tr>
			<td>Dari </td>
			<td>
				<select name="tgl1" id="tgl1" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl1 == ''){
								$s = "selected";
							}else if($i == $tgl1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln1" id="bln1" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln1 == ''){
								$s = "selected";
							}else if($i == $bln1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn1" id="thn1" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn1 == ''){
								$s = "selected";
							}else if($i == $thn1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Urutan</td>
			<td>
				<?php
				$arr_urut=array('nama'=>'Nama','jumlah'=>'Jumlah');
			kombo_from_array("urut","input2",$arr_urut,$urut);
				?>
				
				<?php
				$arr_jenis_urut=array('asc'=>'Ascending','desc'=>'Descending');
			kombo_from_array("jenis_urut","input2",$arr_jenis_urut,$jenis_urut);
				?>
			</td>
		</tr>
		<tr>
			<td>Sampai </td>
			<td>
				<select name="tgl2" id="tgl2" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl2 == ''){
								$s = "selected";
							}else if($i == $tgl2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln2" id="bln2" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln2 == ''){
								$s = "selected";
							}else if($i == $bln2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn2" id="thn2" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn2 == ''){
								$s = "selected";
							}else if($i == $thn2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Tampilkan</td>
			<td><input type="checkbox" value="1" <?php echo $str_jumlah;?> name="jumlah">&nbsp;Jumlah
			&nbsp;&nbsp;<input type="checkbox" <?php echo $str_tarif;?> value="1" name="tarif">&nbsp;Tarif
			&nbsp;&nbsp;<input type="checkbox" <?php echo $str_tarif_ditanggung;?> value="1" name="tarif_ditanggung">&nbsp;Tarif Ditanggung
			</td>
		</tr>
		<tr>
			<td></td>
			<td><input name="submit" id="proses" type="submit" class="button" value="Proses" /></td>
			<td></td>
			<td></td>
		</tr>
	</table>
</form>
<?php
	if($dimensi==1){
	if($periode == 1){
		$tgl1 = "and k.tgl_masuk >= '$thn1-$bln1-$tgl1'";
		$tgl2 = "and k.tgl_masuk <= '$thn2-$bln2-$tgl2'";
	}else if($periode == 2){
		$tgl1 = "and k.tgl_masuk >= '$thn1-$bln1-01'";
		$tgl2 = "and k.tgl_masuk <= '$thn2-$bln2-31'";
	}else{
		$tgl1 = "and k.tgl_masuk >= '$thn1-01-01'";
		$tgl2 = "and k.tgl_masuk <= '$thn2-12-31'";
	}
	
	}else{
		if($periode == 1){
		$tgl1 = "and kl.tgl_masuk >= '$thn1-$bln1-$tgl1'";
		$tgl2 = "and kl.tgl_masuk <= '$thn2-$bln2-$tgl2'";
	}else if($periode == 2){
		$tgl1 = "and kl.tgl_masuk >= '$thn1-$bln1-01'";
		$tgl2 = "and kl.tgl_masuk <= '$thn2-$bln2-31'";
	}else{
		$tgl1 = "and kl.tgl_masuk >= '$thn1-01-01'";
		$tgl2 = "and kl.tgl_masuk <= '$thn2-12-31'";
	}
	}
	
	switch($pilihan1){
		case "prosedur":
			$sql="SELECT * FROM (SELECT DISTINCT md.icd9cm as id ,md.nama_prosedur as nama,
			(SELECT COUNT(icd9cm) AS jumlah FROM klaim_prosedur kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.icd9cm=kl.icd9cm $tgl1 $tgl2) AS jumlah
			FROM klaim_prosedur kl LEFT JOIN master_prosedur md ON md.icd9cm=kl.icd9cm)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "diagnosis":
			$sql="SELECT * FROM (SELECT DISTINCT md.icd10 as id ,md.nama as nama,
			(SELECT COUNT(icd10) AS jumlah FROM klaim_diagnosis kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.icd10=kl.icd10 $tgl1 $tgl2) AS jumlah
			FROM klaim_diagnosis kl LEFT JOIN master_diagnosis md ON md.icd10=kl.icd10)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "tindakan":
			$sql="SELECT * FROM (SELECT DISTINCT md.id_tindakan as id,md.nama_tindakan as nama,
			(SELECT COUNT(id_tindakan) AS jumlah FROM klaim_tindakan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_tindakan=kl.id_tindakan $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif) AS total_tarif FROM klaim_tindakan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_tindakan=kl.id_tindakan $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung) AS total_tarif_ditanggung FROM klaim_tindakan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_tindakan=kl.id_tindakan $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_tindakan kl LEFT JOIN master_tindakan md ON md.id_tindakan=kl.id_tindakan)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "lab":
			$sql="SELECT * FROM (SELECT DISTINCT md.id_lab as id,md.nama_lab as nama,
			(SELECT COUNT(id_lab) AS jumlah FROM klaim_laboratorium kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_lab=kl.id_lab $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif) AS total_tarif FROM klaim_laboratorium kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_lab=kl.id_lab $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung) AS total_tarif_ditanggung FROM klaim_laboratorium kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_lab=kl.id_lab $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_laboratorium kl LEFT JOIN master_lab md ON md.id_lab=kl.id_lab)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "layanan":
			$sql="SELECT * FROM (SELECT DISTINCT md.id_layanan as id,md.layanan as nama,
			(SELECT COUNT(id_layanan) AS jumlah FROM klaim_layanan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_layanan=kl.id_layanan $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif) AS total_tarif FROM klaim_layanan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_layanan=kl.id_layanan $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung) AS total_tarif_ditanggung FROM klaim_layanan kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_layanan=kl.id_layanan $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_layanan kl LEFT JOIN master_layanan md ON md.id_layanan=kl.id_layanan)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "radiologi":
			$sql="SELECT * FROM (SELECT DISTINCT md.id_radiologi as id,md.nama_radiologi as nama,
			(SELECT COUNT(id_radiologi) AS jumlah FROM klaim_radiologi kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_radiologi=kl.id_radiologi $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif) AS total_tarif FROM klaim_radiologi kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_radiologi=kl.id_radiologi $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung) AS total_tarif_ditanggung FROM klaim_radiologi kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_radiologi=kl.id_radiologi $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_radiologi kl LEFT JOIN master_radiologi md ON md.id_radiologi=kl.id_radiologi)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "inacbg":
			$sql="SELECT * FROM (SELECT DISTINCT md.kode_inacbg as id,md.deskripsi as nama,
			(SELECT COUNT(kode_inacbg) AS jumlah FROM klaim_inacbg kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.kode_inacbg=kl.kode_inacbg $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif) AS total_tarif FROM klaim_inacbg kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.kode_inacbg=kl.kode_inacbg $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung) AS total_tarif_ditanggung FROM klaim_inacbg kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.kode_inacbg=kl.kode_inacbg $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_inacbg kl LEFT JOIN master_inacbg md ON md.kode_inacbg=kl.kode_inacbg)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "obat":
			$sql="SELECT * FROM (SELECT DISTINCT md.kode_obat as id,md.nama_obat as nama,
			(SELECT COUNT(id_obat) AS jumlah FROM klaim_obat kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_obat=kl.id_obat $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif*jumlah) AS total_tarif FROM klaim_obat kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_obat=kl.id_obat $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung*jumlah_ditanggung) AS total_tarif_ditanggung FROM klaim_obat kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_obat=kl.id_obat $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_obat kl LEFT JOIN master_obat md ON md.kode_obat=kl.id_obat)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "abhp":
			$sql="SELECT * FROM (SELECT DISTINCT md.id_abhp as id,md.nama as nama,
			(SELECT COUNT(id_abhp) AS jumlah FROM klaim_abhp kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_abhp=kl.id_abhp $tgl1 $tgl2) AS jumlah,
			(SELECT sum(tarif*jumlah) AS total_tarif FROM klaim_abhp kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_abhp=kl.id_abhp $tgl1 $tgl2) AS total_tarif,
			(SELECT sum(tarif_ditanggung*jumlah_ditanggung) AS total_tarif_ditanggung FROM klaim_abhp kld 
			LEFT JOIN klaim k ON kld.id_klaim=k.id_klaim 
			WHERE kld.id_abhp=kl.id_abhp $tgl1 $tgl2) AS total_tarif_ditanggung
			FROM klaim_abhp kl LEFT JOIN master_abhp md ON md.id_abhp=kl.id_abhp)
			AS data_raw ORDER BY $urut $jenis_urut";
		break;
		
		case "1":
			$sql="select d.id_desa as id, d.desa as nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk where klg.id_desa = d.id_desa  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk where klg.id_desa = d.id_desa  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk where klg.id_desa = d.id_desa  $tgl1 $tgl2) as total_tarif_ditanggung
			from desa d inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan 
			where kc.id_kabupaten = '6405' and d.id_kecamatan = '$kecamatan' ORDER BY $urut $jenis_urut";
		break;
		
		case "2":
			$sql="select kc.id_kecamatan as id, kc.kecamatan as nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk inner join desa d on klg.id_desa = d.id_desa 
			where d.id_kecamatan = kc.id_kecamatan  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk inner join desa d on klg.id_desa = d.id_desa 
			where d.id_kecamatan = kc.id_kecamatan  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN 
			keluarga klg ON klg.id_kk = pn.id_kk 
			inner join desa d on klg.id_desa = d.id_desa where d.id_kecamatan = kc.id_kecamatan  $tgl1 $tgl2) as total_tarif_ditanggung
			from kecamatan kc where kc.id_kabupaten = '6405' ORDER BY $urut $jenis_urut";
		break;
		
		case "3":
			$sql="select um.id_umur as id, um.umur as nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk  
			WHERE DATEDIFF(tgl_mulai, pn.tgl_lahir) BETWEEN um.dari AND um.sampai  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			WHERE DATEDIFF(tgl_mulai, pn.tgl_lahir) BETWEEN um.dari AND um.sampai  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			WHERE DATEDIFF(tgl_mulai, pn.tgl_lahir) BETWEEN um.dari AND um.sampai  $tgl1 $tgl2) as total_tarif_ditanggung
			FROM umur um ORDER BY $urut $jenis_urut";
		break;
		
		case "4":
			$sql="select jp.id_jenis_peserta as id, jp.jenis_peserta as nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk  
			where p.id_jenis_peserta = jp.id_jenis_peserta  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where p.id_jenis_peserta = jp.id_jenis_peserta  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where p.id_jenis_peserta = jp.id_jenis_peserta  $tgl1 $tgl2) as total_tarif_ditanggung
			FROM jenis_peserta jp ORDER BY $urut $jenis_urut";
		break;
		
		case "5":
			$sql="select a.id_agama as id, a.agama as nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk  
			where pn.id_agama = a.id_agama  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where pn.id_agama = a.id_agama  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where pn.id_agama = a.id_agama  $tgl1 $tgl2) as total_tarif_ditanggung
			FROM agama a ORDER BY $urut $jenis_urut";
		break;
		
		case "6":
			$sql="select jk.id, jk.nama,
			(SELECT COUNT(id_klaim) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk  
			where pn.jk = jk.id  $tgl1 $tgl2) as jumlah,
			(SELECT sum(total_diminta) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where pn.jk = jk.id  $tgl1 $tgl2) as total_tarif,
			(SELECT sum(total_ditanggung) FROM klaim k inner join peserta p on k.id_peserta = p.id_peserta 
			INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk 
			where pn.jk = jk.id  $tgl1 $tgl2) as total_tarif_ditanggung
			FROM jenis_kelamin jk ORDER BY $urut $jenis_urut";
		break;
	}
		//echo $sql;
		//exit;
		if($_POST['submit'] == 'Proses'){
		//buat 1 dimensi
		if($dimensi=='1'){
			?>
				<table class="tabel">
					<tr>
						<th width="20">NO</th>
						<th>Nama</th>
						<th width="20" style="display:<?php echo $tampil_jumlah;?>">Jumlah</th>
						<th width="50" style="display:<?php echo $tampil_tarif;?>">Total Tarif</th>
						<th width="50" style="display:<?php echo $tampil_tarif_ditanggung;?>">Total Tarif Ditanggung</th>
					</tr>
					<?php
						//echo $sql;
						$qry=mysql_query($sql)or die(mysql_error());
						$jumlah=0;
						$total_tarif=0;
						$total_tarif_ditanggung=0;
							while($hasil=mysql_fetch_array($qry)){
								$no++;
					?>
								<tr>
									<td align="center" ><?php echo $no;?></td>
									<td >
										<?php
										echo $hasil['nama'];
										?>
									</td>
									
									<td align="center" align="right" style="display:<?php echo $tampil_jumlah;?>">
									<?php echo $hasil['jumlah'];?></td>
									<td align="right" style="display:<?php echo $tampil_tarif;?>">
										<?php
										echo format_angka($hasil['total_tarif']);
										?>
									</td>
									<td align="right" style="display:<?php echo $tampil_tarif_ditanggung;?>">
										<?php
										echo format_angka($hasil['total_tarif_ditanggung']);
										?>
									</td>
								</tr>
								
						<?php
								$jumlah = $jumlah + $hasil['jumlah'];
								$total_tarif+=$hasil['total_tarif'];
								$total_tarif_ditanggung+=$hasil['total_tarif_ditanggung'];
							}
						?>
					<tr>
						<td align="center" colspan="2"><b>Jumlah</b></td>
				<td align="center" align="center" style="display:<?php echo $tampil_jumlah;?>">
				<?php echo "<b>$jumlah</b>";?></td>
				<td align="center" align="right" style="display:<?php echo $tampil_tarif;?>">
				<?php echo "<b>".format_angka($total_tarif)."</b>";?></td>
				<td align="center" align="right" style="display:<?php echo $tampil_tarif_ditanggung;?>"><?php echo "<b>".format_angka($total_tarif_ditanggung)."</b>";?></td>
					</tr>
				</table>
			<?php
			
			
		}else{
			//buat 2 dimensi
			include "klaim_dua_dimensi.php";
		}
	}
	
?>